﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.SellStocks;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace MangoMes.Write.API.Applications.SellStockSearchWrite
{
    public class SellStockDeleteHandler : IRequestHandler<SellStockDeleteCommand, ResultsDTO>
    {
        private readonly IBateRepository<SellStock> _sellStockRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="sellStockRepository"></param>
        public SellStockDeleteHandler(IBateRepository<SellStock> sellStockRepository)
        {
            _sellStockRepository = sellStockRepository;
        }
        /// <summary>
        /// 逻辑删除销售出库单
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ResultsDTO> Handle(SellStockDeleteCommand request, CancellationToken cancellationToken)
        {
            var list = new ResultsDTO() { Code = 0 };

            //连接数据库
            DapperHelper dapper = new DapperHelper();
            var conn = dapper.MangoMesWrite;

            //实体
            var sellStock = new SellStock();
            var str = "update sellstock set SellStockState=1 where SellStockId="+request.SellStockId+"";
            var result = _sellStockRepository.Add(str,sellStock,conn);
            if(result != null)
            {
                list.Code = 1;
                list.Message = "删除成功";
            }
            return list;
        }
    }
}
